package com.dq.domain.sys.user;

import com.dq.vo.Vo;
import com.dq.vo.baseVo.VO;
import com.dq.domain.base.BaseEntity;
import com.dq.domain.org.Org;
import com.dq.domain.sys.user.user.base.SysUser;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;

import javax.persistence.Entity;
import javax.persistence.ManyToOne;

/**
 * @author liuhui
 * @date 2019/9/22 0022 11:04:43
 */
@Data
@Entity
@ApiModel("用户账户")
public class UserAccount extends BaseEntity implements Vo.ToVO {
    @ManyToOne
    @ApiModelProperty(value = "用户", hidden = true)
    protected SysUser user;
    @ApiModelProperty(value = "卡号/openId")
    protected String cardNo;
    @ApiModelProperty(value = "卡名称")
    protected String cardName;
    @ApiModelProperty(value = "姓名")
    protected String userName;
    @ApiModelProperty(value = "卡排列顺序", hidden = true)
    protected Long sort;
    @ApiModelProperty(value = "卡类型")
    protected CardType cardType;

    @ManyToOne
    protected Org org;

    public enum CardType {
        wx("微信零钱");
        public String name;

        CardType(String name) {
            this.name = name;
        }
    }

    @Data
    @ApiModel(value = "账户视图")
    public static class Vo implements VO {
        private Long id;
        @ManyToOne
        @ApiModelProperty(value = "用户", hidden = true)
        private SysUser.Vo user;
        @ApiModelProperty(value = "卡号")
        private String cardNo;
        @ApiModelProperty(value = "卡名称", hidden = true)
        private String cardName;
        @ApiModelProperty(value = "姓名")
        private String userName;
        @ApiModelProperty(value = "卡排列顺序", hidden = true)
        private Long sort;
        @ApiModelProperty(value = "卡类型")
        private CardType cardType;
    }

    @Override
    public VO toVO(boolean isRecursion) {
        Vo vo = new Vo();
        vo.id = this.id;
        vo.cardNo = this.cardNo;
        vo.cardName = this.cardName;
        vo.userName = this.userName;
        vo.sort = this.sort;
        vo.cardType = this.cardType;
        return vo;
    }
}
